﻿Imports System
Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Imaging
Namespace Arwani
    Partial Class Exhibitions
        Inherits System.Web.UI.Page
        Protected Division_Lower_Background As String = ""
        Protected Division_Header As String = ""
        Protected Division_Banner As String = ""
        Protected Script_Header As String = ""
        Protected Exhibitions_Category As String = ""
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Call setDivisionSettings()

            Call loadExhibitionCategories()
            Call loadData()
            Call setPageSEOInformation()
        End Sub
        Public Sub setDivisionSettings()
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from division where divisionid=" & CInt(Request.QueryString("divid"))
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            Dim iCount As Integer = 0
            If dtTable.Rows.Count > 0 Then
                '   If Not IsDBNull(dtTable.Rows(0)("divisiontitle")) Then Division_Title = dtTable.Rows(0)("divisiontitle")
                If Not IsDBNull(dtTable.Rows(0)("backgroundimage")) Then Division_Lower_Background = getDivisionImage(dtTable.Rows(0)("backgroundimage"))
                If Not IsDBNull(dtTable.Rows(0)("header_image")) Then Division_Header = getDivisionImage(dtTable.Rows(0)("header_image"))
                If Not IsDBNull(dtTable.Rows(0)("main_banner")) Then Division_Banner = getDivisionImage(dtTable.Rows(0)("main_banner"))
            End If
        End Sub
        Public Sub setPageSEOInformation()
            Dim thisURL As String = Request.Url.AbsoluteUri.Substring(Request.Url.AbsoluteUri.LastIndexOf("/") + 1)
            thisURL = thisURL.Substring(0, thisURL.IndexOf(".aspx") + 5)
            Dim keyword As New HtmlMeta
            keyword.Name = "keyword"


            Dim description As New HtmlMeta
            description.Name = "Description"


            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from AddSEO where PageName='" & thisURL.ToLower() & "'"
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            Dim iCount As Integer = 0
            If dtTable.Rows.Count > 0 Then
                If Not IsDBNull(dtTable.Rows(0)("Title")) Then Page.Title = dtTable.Rows(0)("Title")
                If Not IsDBNull(dtTable.Rows(0)("keywords")) Then keyword.Content = dtTable.Rows(0)("keywords")
                If Not IsDBNull(dtTable.Rows(0)("Description")) Then description.Content = dtTable.Rows(0)("Description")
            End If

            Page.Header.Controls.Add(keyword)
            Page.Header.Controls.Add(description)
        End Sub
        Public Sub loadExhibitionCategories()

            Dim arwCon As New ArwaniController
            Dim strQ As String = "select * from exhibitions_category order by sortorder"
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            Dim iCount As Integer = 0
            Exhibitions_Category = "<ul>"
            Exhibitions_Category &= "<li class='active'><a href='Exhibitions.aspx?catid=0'>All</a></li>"
            If dtTable.Rows.Count > 0 Then
                For iCount = 0 To dtTable.Rows.Count - 1
                    Exhibitions_Category &= "<li><a href='Exhibitions.aspx?&catid=" & dtTable.Rows(iCount)("catid") & "'>" & dtTable.Rows(iCount)("catname") & "</a></li>"
                Next
            End If
            Exhibitions_Category &= "</ul>"

        End Sub
        Public Sub loadData()
            Dim arwCon As New ArwaniController

            Dim strQ As String = ""
            If CInt(Request.QueryString("catid")) = 0 Then
                strQ = "select id,CONCAT(title ,' - ' , description) as TitleDesc ,convert(VARCHAR, convert(datetime, datefrom, 101), 107) + ' '+ convert(VARCHAR, convert(datetime, dateto, 101), 107) as ExhibitionDate from exhibitions order by sortorder"
                'strQ = "select id,CONCAT(title ,' - ' , description) as TitleDesc, CONCAT(CAST(DATE_FORMAT(datefrom,'%b %e, %Y') as char),' ',CAST(DATE_FORMAT(dateto,'%b %e, %Y') as char)) as ExhibitionDate from exhibitions order by sortorder"
            Else
                'strQ = "select id,CONCAT(title ,' - ' , description) as TitleDesc, CONCAT(CAST(DATE_FORMAT(datefrom,'%b %e, %Y') as char),' ',CAST(DATE_FORMAT(dateto,'%b %e, %Y') as char)) as ExhibitionDate from exhibitions where catid=" & CInt(Request.QueryString("catid") & "  order by sortorder")
                strQ = "select id,CONCAT(title ,' - ' , description) as TitleDesc ,convert(VARCHAR, convert(datetime, datefrom, 101), 107) + ' '+ convert(VARCHAR, convert(datetime, dateto, 101), 107) as ExhibitionDate from exhibitions where catid=" & CInt(Request.QueryString("catid")) & "   order by sortorder"
            End If

            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            Me.dgExhibition.DataSource = dtTable
            Me.dgExhibition.DataBind()

        End Sub
        Public Function getDivisionImage(ByVal imgSrc As String) As String
            Dim strReturn As String = "images/division_bg.png"
            If File.Exists(Server.MapPath("Divisions/" & imgSrc)) Then
                strReturn = "Divisions/" & imgSrc
            End If
            Return strReturn
        End Function
        Public Function getImage(ByVal imgSrc As String) As String
            Dim strReturn As String = "images/main_banner.png"
            If File.Exists(Server.MapPath("Exhibitions/" & imgSrc)) Then
                strReturn = "Exhibitions/" & imgSrc
            End If
            Return strReturn
        End Function
        Protected Sub dgExhibition_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgExhibition.ItemDataBound
            Try

                Dim _hyperLink As HyperLink = CType(e.Item.FindControl("_hyperLink"), HyperLink)

                Dim arwCon As New ArwaniController
                Dim ID As Integer = dgExhibition.DataKeys(e.Item.ItemIndex)
                Dim strQ As String = "select * from exhibitions_images where exbid=" & CInt(ID)
                Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
                Dim iCount As Integer = 0
                Dim scriptHTML As String = ""
                Dim strTitle As String = ""
                Dim strDesc As String = ""
                If dtTable.Rows.Count > 0 Then
                    Script_Header &= "api_gallery_" & CInt(ID) & " = ["
                    For iCount = 0 To dtTable.Rows.Count - 1
                        scriptHTML &= "'" & getImage(dtTable.Rows(iCount)("exb_image")) & "',"
                        strTitle &= "'',"
                        strDesc &= "'',"
                    Next
                    scriptHTML = scriptHTML.Substring(0, scriptHTML.Length - 1)
                    strTitle = strTitle.Substring(0, strTitle.Length - 1)
                    strDesc = strDesc.Substring(0, strDesc.Length - 1)
                    Script_Header &= scriptHTML & "];"
                    Script_Header &= "api_titles_" & CInt(ID) & " = [" & strTitle & "];"
                    Script_Header &= "api_descriptions_" & CInt(ID) & " = [" & strDesc & "];"

                Else
                    e.Item.Visible = False
                End If
            Catch ex As Exception

            End Try
        End Sub
    End Class
End Namespace